package com.qianfeng.smartdevices.mapper;
//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼            BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  


import com.qianfeng.smartdevices.pojo.Category;
import com.qianfeng.smartdevices.provider.CategorySqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by jackiechan on 2020/12/9 22:12
 *
 * @Author jackiechan
 */
public interface CategoryMapper {

    @Insert("INSERT INTO categories (categoryname,commandname,txcommand,rxcommand) VALUES(#{categoryname},#{commandname},#{txcommand},#{rxcommand})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()",keyColumn = "id",keyProperty = "id",resultType = Long.class,before = false)
    void addCategory(Category category);

    @UpdateProvider(type = CategorySqlProvider.class, method = "getUpdateSql")
    void updateCategory(Category category);

    @Select("SELECT * FROM categories WHERE id =#{id}")
    Category getCategoryById(Long id);

    @Select("  <script>\n" +
            "\n" +
            "            SELECT *\n" +
            "            FROM categories\n" +
            "            <where>\n" +
            "                <if test=\"categoryname!=null and categoryname != ''\">\n" +
            "                    AND  categoryname like concat('%',#{categoryname},'%')\n" +
            "                </if>\n" +
            "            <if test=\"status!=null and status != '-100'\">\n" +
            "               AND  status =#{status}\n" +
            "            </if>\n" +
            "            </where>\n" +
            "\n" +
            "        </script>")
    List<Category> getAllCategories(@Param("categoryname") String cateoryname, @Param("status") int status);

    @Update("    <script>\n" +
            "\n" +
            "            UPDATE categories SET status='0'\n" +
            "       where id in\n" +
            "            <foreach collection=\"ids\" item=\"id\" separator=\",\" open=\"(\" close=\")\" >\n" +
            "\n" +
            "                #{id}\n" +
            "            </foreach>\n" +
            "\n" +
            "\n" +
            "        </script>\n")
    void deleteCategories(@Param("ids") List<String> ids);

    @Select("SELECT * FROM categories")
    List<Category> findAllCategories();

}
